﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 摇奖机
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //设置属性为false
        bool b = false;
        /// <summary>
        /// 三个随机数赋值给对应label
        /// </summary>
        void RamdonThree()
        {

            Random rd = new Random();
            while (b)
            {
                label1.Text = Convert.ToString(rd.Next(1, 9));
                label2.Text = Convert.ToString(rd.Next(1, 9));
                label3.Text = Convert.ToString(rd.Next(1, 9));
            }
        }
        /// <summary>
        /// 开始摇奖代码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            
            if (button1.Text == "开始摇奖")
            {
                b = true;
                Thread th = new Thread(RamdonThree);       
                th.IsBackground = true;
                th.Start();
                button1.Text = "揭开结果";
            }
            else if(button1.Text == "揭开结果")
            {
                button1.Text = "开始摇奖";
                b = false;
            }
            
        }
        

        private void Form1_Load(object sender, EventArgs e)
        {
            CheckForIllegalCrossThreadCalls = false;
        }
    }
}
